const crypto = require('crypto');
const Response = require('./Response')
const {
	getTime,
} = require('../utils/dateUtils')
const _WebDB = global._WebDB

const _TableName = 'web_song_list'
const _Feild = [
	'list_name',
	'original_create_date',
	'original_create_by',
	// 'favorites_count',
	// 'share_count',
	// 'comment_count',
	// 'play_count',
	// 'profile',
	// 'hot',
	// 'news',
	'list_id',
	'url_source',
	'modify_date'
]

module.exports = {

	/**
	 * 歌单列表
	 * @param  {[type]} params [description]
	 * @return {[type]}        [description]
	 */
	list: async function(params) {
		let {
			source,
			pn = 1,
			ps = 1000,
		} = params
		let result = {}
		let where = (source && source != 'all') ? ` AND url_source = '${source}' ` : ''
		let SQL = `SELECT count(1) AS total FROM ${_TableName} WHERE 1 = 1 ${where}`
		let {
			total
		} = await _WebDB.selectOne(SQL)
		let skip = (pn - 1) * ps
		SQL = `SELECT ${_Feild.join(',')} FROM ${_TableName} WHERE 1 = 1 ${where} LIMIT ${skip}, ${ps}`
		let docs = await _WebDB.select(SQL)
		return new Response('000', '成功', {
			total,
			docs,
		})
	},

}

/**
 * 密码加密
 * @param  {[type]} password [description]
 * @return {[type]}          [description]
 */
function encPwd(password) {
	return crypto.createHash('md5').update(password).digest('hex');
}